/*   1:    */ package org.jetbrains.jsonProtocol;
/*   2:    */ 
/*   3:    */

import com.google.gson.stream.JsonWriter;
import gnu.trove.TIntArrayList;
import gnu.trove.TIntHashSet;
import gnu.trove.TIntProcedure;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */ 
/*  14:    */ public abstract class OutMessage
/*  15:    */ {
/*  16: 15 */   private final StringWriter a = new StringWriter();
/*  17: 16 */   public final JsonWriter writer = new JsonWriter(this.a);
/*  18:    */   private boolean b;
/*  19:    */   
/*  20:    */   protected OutMessage()
/*  21:    */   {
/*  22:    */     try
/*  23:    */     {
/*  24: 22 */       this.writer.beginObject();
/*  25:    */     }
/*  26:    */     catch (IOException localIOException)
/*  27:    */     {
/*  28: 25 */       throw new RuntimeException(localIOException);
/*  29:    */     }
/*  30:    */   }
/*  31:    */   
/*  32:    */   protected void beginArguments()
/*  33:    */     throws IOException
/*  34:    */   {}
/*  35:    */   
/*  36:    */   protected final void writeEnum(String paramString, Enum<?> paramEnum)
/*  37:    */   {
/*  38:    */     try
/*  39:    */     {
/*  40: 34 */       beginArguments();
/*  41: 35 */       this.writer.name(paramString).value(paramEnum.toString());
/*  42:    */     }
/*  43:    */     catch (IOException localIOException)
/*  44:    */     {
/*  45: 38 */       throw new RuntimeException(localIOException);
/*  46:    */     }
/*  47:    */   }
/*  48:    */   
/*  49:    */   protected final void writeMap(String paramString, Map<String, String> paramMap)
/*  50:    */   {
/*  51:    */     try
/*  52:    */     {
/*  53: 44 */       beginArguments();
/*  54: 45 */       this.writer.name(paramString);
/*  55: 46 */       this.writer.beginObject();
/*  56: 47 */       for (Map.Entry localEntry : paramMap.entrySet()) {
/*  57: 48 */         this.writer.name((String)localEntry.getKey()).value((String)localEntry.getValue());
/*  58:    */       }
/*  59: 50 */       this.writer.endObject();
/*  60:    */     }
/*  61:    */     catch (IOException localIOException)
/*  62:    */     {
/*  63: 53 */       throw new RuntimeException(localIOException);
/*  64:    */     }
/*  65:    */   }
/*  66:    */   
/*  67:    */   protected final void writeInt(String paramString, int paramInt)
/*  68:    */   {
/*  69:    */     try
/*  70:    */     {
/*  71: 59 */       beginArguments();
/*  72: 60 */       this.writer.name(paramString).value(paramInt);
/*  73:    */     }
/*  74:    */     catch (IOException localIOException)
/*  75:    */     {
/*  76: 63 */       throw new RuntimeException(localIOException);
/*  77:    */     }
/*  78:    */   }
/*  79:    */   
/*  80:    */   protected final void writeLongArray(String paramString, long[] paramArrayOfLong)
/*  81:    */   {
/*  82:    */     try
/*  83:    */     {
/*  84: 69 */       beginArguments();
/*  85: 70 */       this.writer.name(paramString);
/*  86: 71 */       this.writer.beginArray();
/*  87: 72 */       for (long l : paramArrayOfLong) {
/*  88: 73 */         this.writer.value(l);
/*  89:    */       }
/*  90: 75 */       this.writer.endArray();
/*  91:    */     }
/*  92:    */     catch (IOException localIOException)
/*  93:    */     {
/*  94: 78 */       throw new RuntimeException(localIOException);
/*  95:    */     }
/*  96:    */   }
/*  97:    */   
/*  98:    */   protected final void writeDoubleArray(String paramString, double[] paramArrayOfDouble)
/*  99:    */   {
/* 100:    */     try
/* 101:    */     {
/* 102: 84 */       beginArguments();
/* 103: 85 */       this.writer.name(paramString);
/* 104: 86 */       this.writer.beginArray();
/* 105: 87 */       for (double d : paramArrayOfDouble) {
/* 106: 88 */         this.writer.value(d);
/* 107:    */       }
/* 108: 90 */       this.writer.endArray();
/* 109:    */     }
/* 110:    */     catch (IOException localIOException)
/* 111:    */     {
/* 112: 93 */       throw new RuntimeException(localIOException);
/* 113:    */     }
/* 114:    */   }
/* 115:    */   
/* 116:    */   protected final void writeIntArray(@NotNull String paramString, @NotNull int[] paramArrayOfInt)
/* 117:    */   {
/* 118: 99 */     if (paramString == null) {
/* 119: 99 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jsonProtocol/OutMessage", "writeIntArray" }));
/* 120:    */     }
/* 121: 99 */     if (paramArrayOfInt == null) {
/* 122: 99 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jsonProtocol/OutMessage", "writeIntArray" }));
/* 123:    */     }
/* 124:    */     try
/* 125:    */     {
/* 126: 99 */       beginArguments();
/* 127:100 */       this.writer.name(paramString);
/* 128:101 */       this.writer.beginArray();
/* 129:102 */       for (int k : paramArrayOfInt) {
/* 130:103 */         this.writer.value(k);
/* 131:    */       }
/* 132:105 */       this.writer.endArray();
/* 133:    */     }
/* 134:    */     catch (IOException localIOException)
/* 135:    */     {
/* 136:108 */       throw new RuntimeException(localIOException);
/* 137:    */     }
/* 138:    */   }
/* 139:    */   
/* 140:    */   protected final void writeIntSet(@NotNull String paramString, @NotNull TIntHashSet paramTIntHashSet)
/* 141:    */   {
/* 142:114 */     if (paramString == null) {
/* 143:114 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jsonProtocol/OutMessage", "writeIntSet" }));
/* 144:    */     }
/* 145:114 */     if (paramTIntHashSet == null) {
/* 146:114 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jsonProtocol/OutMessage", "writeIntSet" }));
/* 147:    */     }
/* 148:    */     try
/* 149:    */     {
/* 150:114 */       beginArguments();
/* 151:115 */       this.writer.name(paramString);
/* 152:116 */       this.writer.beginArray();
/* 153:117 */       paramTIntHashSet.forEach(new TIntProcedure()
/* 154:    */       {
/* 155:    */         public boolean execute(int paramAnonymousInt)
/* 156:    */         {
/* 157:    */           try
/* 158:    */           {
/* 159:121 */             OutMessage.this.writer.value(paramAnonymousInt);
/* 160:    */           }
/* 161:    */           catch (IOException localIOException)
/* 162:    */           {
/* 163:124 */             throw new RuntimeException(localIOException);
/* 164:    */           }
/* 165:126 */           return true;
/* 166:    */         }
/* 167:128 */       });
/* 168:129 */       this.writer.endArray();
/* 169:    */     }
/* 170:    */     catch (IOException localIOException)
/* 171:    */     {
/* 172:132 */       throw new RuntimeException(localIOException);
/* 173:    */     }
/* 174:    */   }
/* 175:    */   
/* 176:    */   protected final void writeIntList(@NotNull String paramString, @NotNull TIntArrayList paramTIntArrayList)
/* 177:    */   {
/* 178:139 */     if (paramString == null) {
/* 179:139 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jsonProtocol/OutMessage", "writeIntList" }));
/* 180:    */     }
/* 181:139 */     if (paramTIntArrayList == null) {
/* 182:139 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jsonProtocol/OutMessage", "writeIntList" }));
/* 183:    */     }
/* 184:    */     try
/* 185:    */     {
/* 186:139 */       beginArguments();
/* 187:140 */       this.writer.name(paramString);
/* 188:141 */       this.writer.beginArray();
/* 189:142 */       for (int i = 0; i < paramTIntArrayList.size(); i++) {
/* 190:143 */         this.writer.value(paramTIntArrayList.getQuick(i));
/* 191:    */       }
/* 192:145 */       this.writer.endArray();
/* 193:    */     }
/* 194:    */     catch (IOException localIOException)
/* 195:    */     {
/* 196:148 */       throw new RuntimeException(localIOException);
/* 197:    */     }
/* 198:    */   }
/* 199:    */   
/* 200:    */   protected final void writeSingletonIntArray(@NotNull String paramString, @NotNull int paramInt)
/* 201:    */   {
/* 202:154 */     if (paramString == null) {
/* 203:154 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jsonProtocol/OutMessage", "writeSingletonIntArray" }));
/* 204:    */     }
/* 205:    */     try
/* 206:    */     {
/* 207:154 */       beginArguments();
/* 208:155 */       this.writer.name(paramString);
/* 209:156 */       this.writer.beginArray();
/* 210:157 */       this.writer.value(paramInt);
/* 211:158 */       this.writer.endArray();
/* 212:    */     }
/* 213:    */     catch (IOException localIOException)
/* 214:    */     {
/* 215:161 */       throw new RuntimeException(localIOException);
/* 216:    */     }
/* 217:    */   }
/* 218:    */   
/* 219:    */   protected final <E extends OutMessage> void writeList(String paramString, List<E> paramList)
/* 220:    */   {
/* 221:166 */     if ((paramList == null) || (paramList.isEmpty())) {
/* 222:167 */       return;
/* 223:    */     }
/* 224:    */     try
/* 225:    */     {
/* 226:171 */       beginArguments();
/* 227:172 */       this.writer.name(paramString);
/* 228:173 */       this.writer.beginArray();
/* 229:174 */       int i = 0;
/* 230:175 */       for (OutMessage localOutMessage : paramList)
/* 231:    */       {
/* 232:176 */         if (i != 0) {
/* 233:177 */           this.a.append(',').append(' ');
/* 234:    */         } else {
/* 235:180 */           i = 1;
/* 236:    */         }
/* 237:183 */         StringBuffer localStringBuffer = localOutMessage.a.getBuffer();
/* 238:184 */         if (!localOutMessage.b)
/* 239:    */         {
/* 240:185 */           localOutMessage.b = true;
/* 241:    */           try
/* 242:    */           {
/* 243:187 */             localOutMessage.writer.endObject();
/* 244:    */           }
/* 245:    */           catch (IllegalStateException localIllegalStateException)
/* 246:    */           {
/* 247:190 */             if ("Nesting problem.".equals(localIllegalStateException.getMessage())) {
/* 248:191 */               throw new RuntimeException(localOutMessage.a.getBuffer() + "\nparent:\n" + this.a.getBuffer(), localIllegalStateException);
/* 249:    */             }
/* 250:194 */             throw localIllegalStateException;
/* 251:    */           }
/* 252:    */         }
/* 253:199 */         this.a.append(localStringBuffer);
/* 254:    */       }
/* 255:201 */       this.writer.endArray();
/* 256:    */     }
/* 257:    */     catch (IOException localIOException)
/* 258:    */     {
/* 259:204 */       throw new RuntimeException(localIOException);
/* 260:    */     }
/* 261:    */   }
/* 262:    */   
/* 263:    */   protected final void writeStringList(String paramString, List<String> paramList)
/* 264:    */   {
/* 265:    */     try
/* 266:    */     {
/* 267:210 */       beginArguments();
/* 268:211 */       JsonWriters.writeStringList(this.writer, paramString, paramList);
/* 269:    */     }
/* 270:    */     catch (IOException localIOException)
/* 271:    */     {
/* 272:214 */       throw new RuntimeException(localIOException);
/* 273:    */     }
/* 274:    */   }
/* 275:    */   
/* 276:    */   public static void prepareWriteRaw(OutMessage paramOutMessage, String paramString)
/* 277:    */     throws IOException
/* 278:    */   {
/* 279:219 */     paramOutMessage.writer.name(paramString).nullValue();
/* 280:220 */     StringBuffer localStringBuffer = paramOutMessage.a.getBuffer();
/* 281:221 */     localStringBuffer.delete(localStringBuffer.length() - "null".length(), localStringBuffer.length());
/* 282:    */   }
/* 283:    */   
/* 284:    */   public static void doWriteRaw(OutMessage paramOutMessage, String paramString)
/* 285:    */   {
/* 286:225 */     paramOutMessage.a.append(paramString);
/* 287:    */   }
/* 288:    */   
/* 289:    */   protected final void writeMessage(String paramString, OutMessage paramOutMessage)
/* 290:    */   {
/* 291:    */     try
/* 292:    */     {
/* 293:230 */       beginArguments();
/* 294:231 */       prepareWriteRaw(this, paramString);
/* 295:    */       
/* 296:233 */       StringBuffer localStringBuffer = paramOutMessage.a.getBuffer();
/* 297:234 */       if (!paramOutMessage.b) {
/* 298:235 */         paramOutMessage.close();
/* 299:    */       }
/* 300:237 */       this.a.append(localStringBuffer);
/* 301:    */     }
/* 302:    */     catch (IOException localIOException)
/* 303:    */     {
/* 304:240 */       throw new RuntimeException(localIOException);
/* 305:    */     }
/* 306:    */   }
/* 307:    */   
/* 308:    */   public void close()
/* 309:    */     throws IOException
/* 310:    */   {
/* 311:245 */     assert (!this.b);
/* 312:246 */     this.b = true;
/* 313:247 */     this.writer.endObject();
/* 314:248 */     this.writer.close();
/* 315:    */   }
/* 316:    */   
/* 317:    */   protected final void writeLong(String paramString, long paramLong)
/* 318:    */   {
/* 319:    */     try
/* 320:    */     {
/* 321:253 */       beginArguments();
/* 322:254 */       this.writer.name(paramString).value(paramLong);
/* 323:    */     }
/* 324:    */     catch (IOException localIOException)
/* 325:    */     {
/* 326:257 */       throw new RuntimeException(localIOException);
/* 327:    */     }
/* 328:    */   }
/* 329:    */   
/* 330:    */   protected final void writeDouble(String paramString, double paramDouble)
/* 331:    */   {
/* 332:    */     try
/* 333:    */     {
/* 334:263 */       beginArguments();
/* 335:264 */       this.writer.name(paramString).value(paramDouble);
/* 336:    */     }
/* 337:    */     catch (IOException localIOException)
/* 338:    */     {
/* 339:267 */       throw new RuntimeException(localIOException);
/* 340:    */     }
/* 341:    */   }
/* 342:    */   
/* 343:    */   protected final void writeBoolean(String paramString, boolean paramBoolean)
/* 344:    */   {
/* 345:    */     try
/* 346:    */     {
/* 347:273 */       beginArguments();
/* 348:274 */       this.writer.name(paramString).value(paramBoolean);
/* 349:    */     }
/* 350:    */     catch (IOException localIOException)
/* 351:    */     {
/* 352:277 */       throw new RuntimeException(localIOException);
/* 353:    */     }
/* 354:    */   }
/* 355:    */   
/* 356:    */   protected final void writeString(String paramString1, String paramString2)
/* 357:    */   {
/* 358:282 */     if (paramString2 != null) {
/* 359:283 */       writeNullableString(paramString1, paramString2);
/* 360:    */     }
/* 361:    */   }
/* 362:    */   
/* 363:    */   protected final void writeNullableString(String paramString1, String paramString2)
/* 364:    */   {
/* 365:    */     try
/* 366:    */     {
/* 367:289 */       beginArguments();
/* 368:290 */       this.writer.name(paramString1).value(paramString2);
/* 369:    */     }
/* 370:    */     catch (IOException localIOException)
/* 371:    */     {
/* 372:293 */       throw new RuntimeException(localIOException);
/* 373:    */     }
/* 374:    */   }
/* 375:    */   
/* 376:    */   public final CharSequence toJson()
/* 377:    */   {
/* 378:299 */     return this.a.getBuffer();
/* 379:    */   }
/* 380:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jsonProtocol.OutMessage

 * JD-Core Version:    0.7.0.1

 */